package base;

import java.util.Random;

/**
 * Generate exponentiel number via the nextInt() method.
 * 
 * @author rweiller
 * 
 */
public class Exponentiel
{
	public Random	x;
	public int		m;

	/**
	 * Create an exponentiel generator
	 * 
	 * @param seed the first seed
	 * @param m the medium
	 */
	public Exponentiel(int seed, int m)
	{
		this.x = new Random(seed);
		if (m < 1)
			throw new IllegalArgumentException("Config file : sim.exp.m must be > 0");
		this.m = m;
	}

	/**
	 * Return the next exponentiel number
	 * 
	 * @return the next exponentiel number
	 */
	public int nextInt()
	{
		int aNumber = 0;
		while (aNumber < 1)
		{
			aNumber = (int) Math.round(-m * Math.log(x.nextDouble()));
		}
		return aNumber;
	}
}
